<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ name: 'wel' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>权限管理</el-breadcrumb-item>
            <el-breadcrumb-item>权限列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card>
            <el-table
                    :data="infoList"
                    v-loading="is_loading"
                    border
                    stripe
            >
                <!--索引列 -->
                <el-table-column align="center" type="index" label="#"></el-table-column>
                <el-table-column align="center" label="权限名称" prop="authName"></el-table-column>
                <el-table-column align="center" label="路径" prop="path"></el-table-column>
                <el-table-column align="center" label="权限等级" prop="level">
                    <template slot-scope="scope">
                        <el-tag
                                :type="tagtype(scope.row.level)"
                                disable-transitions>{{scope.row.level | numToCase}}级
                        </el-tag>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script>
    import $axios from '../../network/request'

    export default {
        name: "Rights",
        data() {
            return {
                //初始化数据
                infoList: [],
            }
        },
        methods: {
            //初始化请求
            init() {
                $axios({
                    method: 'get',
                    url: 'rights/list'
                }).then(res => {
                    if (res.data.meta.status !== 200) {
                        this.$message.error("数据请求异常")
                    } else {
                        this.infoList = res.data.data
                    }
                })
            }
        },
        created() {
            this.init()
        },
        computed: {
            //获取store的加载
            is_loading() {
                return this.$store.state.is_loading
            },
            //计算属性返回一个function，通过判断计算属性
            tagtype() {
                return function (val) {
                    switch (val) {
                        case '0':
                            return 'success'
                        case '1':
                            return 'primary'
                        default:
                            return 'warning'
                    }
                }
            }
        },
        //过滤,  v  是被过滤的值
        filters: {
            numToCase(v) {
                switch (v) {
                    case '0':
                        return '一'
                    case '1':
                        return '二'
                    default:
                        return '三'
                }
            }
        },

    }
</script>

<style scoped>

</style>
